var manualCodeApp = angular.module("manualCode", []);
manualCodeApp.controller("againScanController", function($scope, $rootScope, $window, scCodeService, Popup, $location) {
    var token = localStorage.getItem("token");
    var openCharge = localStorage.getItem("openCharge");
    // alert(openCharge);
    if(openCharge == "true"){
    	$location.path("/charging");
    }else{
	    //手动输入二维码
	    $scope.manualCode = function() {
	        var postData = {
	            qrCode: $scope.qrCode
	        }
	        if (!postData.qrCode || postData.qrCode == undefined) {
	            Popup.notice('请输入二维码', 3000, function() {
	                console.log('ok')
	            });
	        } else {	        	
	            scCodeService.getChargerDetailByQrCode(postData).then(function(data) {
	            	//alert(JSON.stringify(data));
	            	document.getElementById("loadingManual").style.display = "block";
	                if (data.code == "200") {
	                	document.getElementById("loadingManual").style.display = "none";
				    	$scope.chargerDetail = data.data;
				    	// alert(JSON.stringify($scope.chargerDetail));
						localStorage.setItem("chargerDetail",JSON.stringify($scope.chargerDetail));
	                    $location.path("/chargeStarted");
	                } else {
	                	document.getElementById("loadingManual").style.display = "none";
	                	$scope.qrCode = "";
                        Popup.notice('二维码错误，请重新输入', 3000, function() {

						});
	                }
	            })
	        }
	    }
    }
})
